package com.example.demo.entity.security;

import com.alibaba.fastjson.JSON;
import com.example.demo.entity.Result;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: 未登录
 * @author: cj
 * @create: 09-02-08 09:31:05
 */
@Component
public class LoginEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest httpServletRequest,
                         HttpServletResponse response, AuthenticationException e)
            throws IOException {
        Result result = new Result();

        result.setStatus( 401 );
        result.setMessage( "未登录~~" );

        response.setCharacterEncoding( "UTF-8" );

        response.getWriter().write( JSON.toJSONString( result ) );
    }

    public static void main(String[] args) {
        int a = 00044;
        System.out.println(a);
    }
}
